package com.yfh.sharding.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {


    @Profile({"dev", "test"})
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        /**
         * 该集合作用是给swagger2测试接口的时候添加头部信息
         */
//        ArrayList<Parameter> pars = Lists.newArrayList();
//        //token参数
//        ParameterBuilder tokenPar = new ParameterBuilder();
//        tokenPar.name("authorization")
//                .description("swagger测试用（模拟authorization传入）非必填header")
//                .modelRef(new ModelRef("String"))
//                .parameterType("header")
//                .required(false);
//
//        //需要刷新的token参数
//        ParameterBuilder refreshTokenPar = new ParameterBuilder();
//        refreshTokenPar.name("refresh_token")
//                .description("swagger测试用（模拟刷新token传入）非必填header")
//                .modelRef(new ModelRef("String"))
//                .parameterType("header")
//                .required(false);
//        pars.add(tokenPar.build());
//        pars.add(refreshTokenPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 分组名称
                .groupName("淮南交易中心")
                .select()
                // 这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.yfh.huainan.controller"))
                .paths(PathSelectors.any())
                .build()
//                .globalOperationParameters(pars)
                .enable(true);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("淮南交易中心")
                .description("交易中心swagger2")
                .termsOfServiceUrl("com.yfh.huainan")
                .version("1.0-SNOPSHOT")
                .build();
    }
}